package com.intellij.licensecommon.data;

public class LicenseImpl {
    private final String username;
    private final String key;
    public static final String c = "License Server";

    public LicenseImpl(String username, String key) {
        this.username = username;
        this.key = key;
    }

    private LicenseImpl(LicenseData licenseData) {
        this(licenseData.getUsername(), licenseData.getKey());
    }

    public static LicenseImpl toLicense(LicenseData licenseData) {
        if (licenseData == null) {
            return null;
        }
        return new LicenseImpl(licenseData);
    }

    public static LicenseData toLicenseData(LicenseImpl license) {
        if (license == null) {
            return null;
        }
        return new SubscriptionLicenseDataImpl(license.getKey(), license.getUsername());
    }

    public String getUsername() {
        return this.username;
    }

    public String getKey() {
        return this.key;
    }

    public String toString() {
        return "LicenseImpl{" + this.username + ":" + this.key + "}";
    }

    public boolean equals(Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof LicenseImpl)) {
            return false;
        }
        LicenseImpl localf = (LicenseImpl) other;
        if (this.key == null ? localf.key != null : !this.key.equals(localf.key)) {
            return false;
        }
        return this.username == null ? false : localf.username == null ? true : this.username.equals(localf.username);
    }

    public int hashCode() {
        int i = this.username != null ? this.username.hashCode() : 0;
        i = 29 * i + (this.key != null ? this.key.hashCode() : 0);
        return i;
    }
}

